//
//  CJScreen.swift
//  CJCore
//
//  Created by 陈警卫 on 2024-06-03.
//

/*
  (+: Plus, m: mini, P:Pro, PM: ProMax)
 
 iPhone 15+/15PM        430x932  1290x2796  @3x  6.7
 iPhone 15/15P          393x852  1179x2556  @3x  6.1
 iPhone 14PM            430x932  1290x2796  @3x  6.7
 iPhone 14P             393x852  1179x2556  @3x  6.1
 iPhone 14+             428x926  1284x2778  @3x  6.7
 iPhone 14              390x844  1170x2532  @3x  6.1
 iPhone 13PM            428*926  1284*2778  @3x  6.7
 iPhone 13/13P          390*844  1170*2532  @3x  6.1
 iPhone 13m             360*780  1080*2340  @3x  5.4
 iPhone 12PM            428*926  1284*2778  @3x  6.7
 iPhone 12m             375*812  1080*2340  @3x  5.4
 iPhone 12/12P          390*844  1170*2532  @3x  6.1
 iPhone XsM/11PM        414*896  1242*2688  @3x  6.5
 iPhone Xr/11           414*896  828*1792   @2x  6.1
 iPhone X/Xs/11P        375*812  1125*2436  @3x  5.8
 iPhone 6+/6S+/7+/8+    414*736  1242*2208  @3x  5.5
 iPhone 6/6S/7/8/SE2    375*667  750*1334   @2x  4.7
 iPhone 5/5S/5c/SE      320*568  640*1136   @2x  4.0
 iPhone 4/4s            320*480  640*960    @2x  3.5
 
 */

import UIKit
import Foundation

open class CJScreen: NSObject {

    @objc static public var bounds: CGRect {
        return UIScreen.main.bounds
    }
    
    @objc static public var size: CGSize {
        return UIScreen.main.bounds.size
    }
    
    @objc static public var width: CGFloat {
        return UIScreen.main.bounds.width
    }
    
    @objc static public var height: CGFloat {
        return UIScreen.main.bounds.height
    }
    
    /// keyWindow
    @objc static public var keyWindow: UIWindow? {
        if #available(iOS 13.0, *) {
            let winScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
            return winScene?.windows.first
        } else {
            return UIApplication.shared.keyWindow
        }
    }
    
    /// normalWindow
    @objc static public var normalWindow: UIWindow? {
        for window in UIApplication.shared.windows {
            if window.windowLevel == .normal {
                return window
            }
        }
        return nil
    }
    
    /// window
    @objc static public var window: UIWindow? {
        var window = UIApplication.shared.delegate?.window
        if window == nil {
            window = keyWindow
        }
        if window == nil {
            window = normalWindow
        }
        guard let window = window else {
            return nil
        }
        return window
    }
    
    /// 电池栏高度
    @objc static public var batBarHeight: CGFloat {
        if #available(iOS 13.0, *) {
            let height = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
            return height
        } else {
            let height = UIApplication.shared.statusBarFrame.height
            return height
        }
    }
    
    /// 下巴高度
    @objc static public var bottomBarHeight: CGFloat {
        if #available(iOS 11.0, *) {
            let height = window?.safeAreaInsets.bottom ?? 0
            return height
        } else {
            return 0
        }
    }
    
    /// 判断刘海屏
    @objc static public var isScreenBangs: Bool {
        if bottomBarHeight > 0 {
            return true
        } else {
            return false
        }
    }
    
    /// 导航栏高度
    @objc static public let navBarHeight: CGFloat = 44.0
    @objc static public let navBatBarHeight: CGFloat = navBarHeight + batBarHeight
    /// tab高度
    @objc static public let tabBarHeight: CGFloat = 49.0
    @objc static public let tabBottomHeight: CGFloat = tabBarHeight + bottomBarHeight
    
    /// 基础尺寸
    @objc static public let baseSize: CGSize = CGSize(width: 357.0, height: 667.0)
    /// 基础宽度比例
    @objc static public let scaleWidth = width/baseSize.width
    
}
